#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;

const int MAX_SIZE = 2*100000;

char st[MAX_SIZE];
int top = 0;

inline bool is_empty(){
	return top == 0;
}

inline bool is_full(){
	return top == MAX_SIZE;
}

inline void push(int data){
	if(!is_full())
		st[top++] = data;
}

inline void pop(){
	if(!is_empty())
		top--;
}

inline int get_top(){
	return st[top-1];
}

int main(){
	int n;
	cin>>n;
	string s;
	char tmp;
	for(int i=0;i<n;i++){
		cin>>s;
		int length = sizeof(s);
		for(int j=0;i<length;i++){
			tmp = s[i];
			if(tmp == '<'||tmp == 40||tmp =='['||tmp ==123){
				push(tmp);
			}else{
				if(!is_empty()){
					char last = get_top();
					if((last == '<' && tmp == '>') || (last == '[' && tmp == ']') || (last == 123 && tmp == 125) || (last == 40 && tmp == 41)){
						pop();
					}else{
						cout<<"FALSE"<<endl;
						return 0;
					}
				}else{
					cout<<"FALSE"<<endl;
					return 0;
				}
			}
		}
		if(!is_empty())	cout<<"FALSE"<<endl;
		else	cout<<"TRUE"<<endl;
		top = 0;
		
	}
	return 0;
	
}


